/**
 * @计算单词的个数
 * @ 怎样能够处理单词中的(')号，比如we're看成是一个单词
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>

int countWords(const char string[]);
bool alphabetic(const char c);

int main(int argc, char *argv[]) {
	const char text1[] = {"well, he're goes."};
	const char text2[] = {"and here we g'o again."};

	printf("%s - words = %d\n", text1, countWords(text1));
	printf("%s - words = %d\n", text2, countWords(text2));

	return 0;
}

int countWords(const char string[]) {
	int i, word_count = 0;
	bool is_in_word = true;

	for (i=0; string[i] != '\0'; i++) {
		if (alphabetic(string[i])) {
			is_in_word = true;
		} else {
			if (is_in_word == true) {
				word_count++;
			}
			is_in_word = false;
		}

	}

	return word_count;
}

bool alphabetic(const char c) {
	if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '\'')) {
		return true;
	} else {
		return false;
	}
}
